import Vue from 'vue';
import Axios from 'axios';
import ApiUrl from '@/constant/ApiUrl.ts';
import {Route} from 'vue-router';

export default class Activity extends Vue {
    public api = ApiUrl;
    public imageFileDoamin = 'http://wx.chuangyijiaoyu2018.com/';


    public constructor() {
        super();

        if (process.env.NODE_ENV === 'development') {
            ApiUrl.url = '/site';
        }
        // if (window.history && window.history.pushState) {
        //     window.addEventListener('popstate', (e) => {
        //         window.history.pushState('', '', '');
        //     });
        // }
    }

    public navigateTo(obj: any): void {
        obj.params = {...obj.params, referer: this.$route.name};
        this.$router.push(obj);
    }

    public navigateBack(n: number = -1): void {
        if (this.$route.params.referer) {
            this.$router.go(n);
        } else {
            this.reLaunch();
        }
    }

    public reLaunch(): void {
        this.$router.replace({path: '/'});
    }

    public redirectTo(obj: any = {}): void {
        if (!obj.name && !obj.path) {
            this.$router.replace({path: '/'});
        } else {
            this.$router.replace(obj);
        }
    }

    public navigateLoginPage(): void {
        this.navigateTo({
            name: 'login',
            query: {redirect: this.$route.fullPath},
        });
    }

    public imageUrlHandle(str: string): string {
        return this.imageFileDoamin + String(str);
    }
}
